package com.rcadmin.busi.admin.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.rcadmin.busi.admin.ddl.SysMenu;
import com.rcadmin.common.contant.IsEff;
import com.rcadmin.core.jpa.BaseDao;
import com.rcadmin.core.jpa.DaoException;

/**
 * 系统菜单DAO
 * 
 * @author tanson lam
 * @create 2016年9月6日
 */
@Component
public class SysMenuDao {
	@Resource
	private BaseDao baseDao;

	/**
	 * 获取所有的菜单
	 * 
	 * @return
	 */
	public List<SysMenu> getAllMenu() {
		return baseDao.find(" iseff='" + IsEff.EFFECTIVE
				+ "' order by parentid,sort", SysMenu.class);
	}

	/**
	 * 获取导航菜单第一位菜单设置
	 * 
	 * @return
	 * @throws DaoException
	 */
	public SysMenu queryFirstTopMenu() {
		List<SysMenu> menuList = baseDao.find(
				" level=1 and iseff='1' order by sort", SysMenu.class);
		if (!menuList.isEmpty()) {
			return menuList.get(0);
		}
		return null;
	}
}
